<?php get_header(); ?>
<div class="inner">
<div class="top-cont">  
<?php
if(is_front_page() || is_home()){}else{
  if($post->post_parent)
  $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
  else
  $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
  if ($children) { ?>
    
        <div class="second-nav">
            <ul>
                <?php echo $children; ?>
            </ul>
        </div>

    <!-- Sub Page Banner Start -->
  	<?php }   ?>    
	<?php if ( has_post_thumbnail()) {?>
   
        <div id="sub-banner" class="row">
            <?php
            // getting featured image start
                $image_id = get_post_thumbnail_id ( $post->ID );
                //$image_url = wp_get_attachment_image_src($image_id, array(980,228),true);
				$image_url = cs_attachment_image_src($image_id, 1080, 228);
                echo "<img src='".$image_url."' />";
            // getting featured image end
            ?>
        </div> 
    <?php }?>

    <!-- Sub Page Banner End -->
    <div class="clear"></div>    
<?php }?>
</div>
    <!-- Container Start -->
<?php


$cs_page_builder = get_post_meta($post->ID, "cs_page_builder", true);
	if($cs_page_builder == ''){
		// Sample page
		if(is_page(2) or is_page('sample-page') or is_page('Sample Page') ){
		?>
			<div class="container row">
			<div class="sixteen columns left">
				<?php 	
					wp_reset_query();
					get_template_part( 'loop', 'page' );
				?>
				</div>
			</div>
			</div>
		<?php
		}
		// Sample Page End
	}
	else {
	$xmlObject = new SimpleXMLElement($cs_page_builder);
		$cs_layout = $xmlObject->cs_layout;
		$cs_sidebar_left = $xmlObject->cs_sidebar_left;
		$cs_sidebar_right = $xmlObject->cs_sidebar_right;
			if ( $cs_layout == "left" ) {
				$cs_layout = "two-thirds column right";
				$show_sidebar = $cs_sidebar_left;
			}
			else if ( $cs_layout == "right" ) {
				$cs_layout = "two-thirds column left";
				$show_sidebar = $cs_sidebar_right;
			}
			else $cs_layout = "sixteen columns left";

?>
    <div class="container row">
        <div class="<?php echo $cs_layout;?>">
<?php
				$counter_gal = 0;
					foreach ( $xmlObject->children() as $node ){
						if ( $node->getName() == "rich_editor" ) {
							wp_reset_query();
							//get_template_part( 'loop', 'page' );
								if ( $node->cs_rich_editor_title == "Yes") echo '<h1 class="heading">'.get_the_title().'</h1>';
								if ( $node->cs_rich_editor_desc == "Yes") {
									$content_of_post = get_post($post->ID);
									$content = $content_of_post->post_content;
									$content = apply_filters('the_content', $content);
									//$content = str_replace(']]>', ']]>', $content);
									echo '<div class="in-sec in-sec-nopad"><div class="pagetxt">'.$content.'</div></div>';
								}
						}
						if ( $node->getName() == "gallery" ) {
							$counter_gal++;
							$cs_gal_layout_db = $node->layout;
							$cs_gal_album_db = $node->album;
							$cs_gal_title_db = $node->title;
							$cs_gal_desc_db = $node->desc;
							$cs_gal_pagination_db = $node->pagination;
							$cs_gal_media_per_page_db = $node->media_per_page;
								include("page_gallery.php");
						}
						else if ( $node->getName() == "slider" ) {
							$counter_gal++;
							include("page_slider.php");
						}
						else if ( $node->getName() == "event" ) {
							$counter_gal++;
							include("page_event.php");
							//get_template_part( 'page', 'event' );
						}
						else if ( $node->getName() == "blog" ) {
							$counter_gal++;
								$cs_blog_title_db = $node->cs_blog_title;
								$cs_blog_cat_db = $node->cs_blog_cat;
								$cs_blog_excerpt_db = $node->cs_blog_excerpt;
								$cs_blog_num_post_db = $node->cs_blog_num_post;
								$cs_blog_pagination_db = $node->cs_blog_pagination;
								include("page_blog.php");
						}
						else if ( $node->getName() == "audio" ) {
							$counter_gal++;
								$cs_audio_title_db = $node->cs_audio_title;
								$cs_audio_cat_db = $node->cs_audio_cat;
								$cs_audio_excerpt_db = $node->cs_audio_excerpt;
								$cs_audio_num_post_db = $node->cs_audio_num_post;
								$cs_audio_pagination_db = $node->cs_audio_pagination;
								include("page_audio.php");
						}
						else if ( $node->getName() == "video" ) {
							$counter_gal++;
								$cs_video_title_db = $node->cs_video_title;
								$cs_video_cat_db = $node->cs_video_cat;
								$cs_video_excerpt_db = $node->cs_video_excerpt;
								$cs_video_num_post_db = $node->cs_video_num_post;
								$cs_video_pagination_db = $node->cs_video_pagination;
								include("page_video.php");
						}
						else if ( $node->getName() == "contact" ) {
							$counter_gal++;
								$cs_contact_email_db = $node->cs_contact_email;
								$cs_contact_succ_msg_db = $node->cs_contact_succ_msg;
								$cs_contact_map_db = $node->cs_contact_map;
								include("page_contact.php");
						}
						else if ( $node->getName() == "news" ) {
							$counter_gal++;
								$cs_news_title_db = $node->cs_news_title;
								$cs_news_cat_db = $node->cs_news_cat;
								$cs_news_excerpt_db = $node->cs_news_excerpt;
								$cs_news_num_post_db = $node->cs_news_num_post;
								$cs_news_pagination_db = $node->cs_news_pagination;
								include("page_news.php");
						}
						else if ( $node->getName() == "album" ) {
							$counter_gal++;
								$cs_album_layout_db = $node->cs_album_layout;
								$cs_album_cat_db = $node->cs_album_cat;
								$cs_album_cat_show_db = $node->cs_album_cat_show;
								$cs_album_filterable_db = $node->cs_album_filterable;
								$cs_album_title_db = $node->cs_album_title;
								$cs_album_buynow_db = $node->cs_album_buynow;
								$cs_album_pagination_db = $node->cs_album_pagination;
								$cs_album_per_page_db = $node->cs_album_per_page;
								include("page_album.php");
						}						
					}
				
?>
    </div>
    <!-- two-thirds end -->
    <?php if($cs_layout != "sixteen columns left"){?>
    <!--Sidebar Start-->
        <div class="one-third column left">
            <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar($show_sidebar) ) : ?>
			<?php endif; ?>   
        </div>
	<?php }?>
    <!--Sidebar Ends-->    
	<div class="clear"></div>
</div><!-- Page End -->
<?php
}
get_footer();
?>
<?php //get_sidebar(); ?>